package com.infraware.supermanbooks;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.Iterator;

import nl.siegmann.epublib.domain.Resource;
import nl.siegmann.epublib.domain.Resources;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;

public class BookResourceProvider extends ContentProvider {

    private static final String TAG = "BookResourceProvider";

    public BookResourceProvider() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public boolean onCreate() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getType(Uri uri) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
        String scheme = uri.getScheme();
        String path = uri.getPath();
        String host = uri.getHost();
        String lastPathSegment = uri.getLastPathSegment();
        String fragment = uri.getFragment();
        Log.d(TAG, "[openFile] uri => " + uri);
        Log.d(TAG, "[openFile] scheme => " + scheme);
        Log.d(TAG, "[openFile] path => " + path);
        Log.d(TAG, "[openFile] host => " + host);
        Log.d(TAG, "[openFile] lastPathSegment => " + lastPathSegment);
        Log.d(TAG, "[openFile] fragment => " + fragment);

        Resources resources = BookDetailFragment.book.getResources();
        Resource resource = resources.getByHref(path);
        if (path.endsWith(resource.getHref())) {
            Log.d(TAG, "[openFile] href => " + resource.getHref());
        }
        return super.openFile(uri, mode);
    }

}
